package com.ficus.road.maintain.dao;

import com.ficus.road.maintain.core.dao.BaseMongoDao;
import com.ficus.road.maintain.core.model.GpsHistory;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.index.Index;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class GpsHistoryMinuteDao extends BaseMongoDao<GpsHistory, String> {
    @Override
    public void indexOperation() {
        super.getMongoTemplate().indexOps(getCollectionName()).ensureIndex(new Index().on("timestamp", Sort.Direction.DESC).background());
        super.getMongoTemplate().indexOps(getCollectionName()).ensureIndex(new Index().on("creation_time", Sort.Direction.DESC).expire(60, TimeUnit.DAYS).background());
        super.getMongoTemplate().indexOps(getCollectionName()).ensureIndex(new Index().on("car_id", Sort.Direction.DESC).background());
    }

    @Override
    public String getCollectionName() {
        return "gps_history_minute";
    }
}
